2020-2021 Sunseeker Telemetry and Lighting System
sd24_ex1_continuousConversionGroupChannels.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 //******************************************************************************
33 // MSP430i20xx SD24 Example 01 - SD24, Continuous Conversion on a Group of 3 Channels
34 //
35 // Description: This program uses the SD24 module to perform continuous
36 // conversions on a group of channels (0, 1 and 2). A SD24 interrupt occurs
37 // whenever the conversions have completed.
38 //
39 // Test by applying voltages to the 3 input channels and setting a breakpoint
40 // at the indicated line. Run program until it reaches the breakpoint, then use
41 // the debugger's watch window to view the conversion results.
42 //
43 // Results (upper 16 bits only) are stored in three arrays, one for each channel.
44 //
45 // ACLK = 32kHz, MCLK = SMCLK = Calibrated DCO = 16.384MHz, SD_CLK = 1.024MHz
46 // * Ensure low_level_init.c is included when building/running this example *
47 //
48 // Notes: For minimum Vcc required for SD24 module - see datasheet
49 // 100nF cap btw Vref and AVss is recommended when using 1.2V ref
50 //
51 // MSP430i20xx
52 // -----------------
53 // /|\| |
54 // | | |
55 // --|RST |
56 // | |
57 // Vin1+ -->|A0.0+ VREF |---+
58 // Vin1- -->|A0.0- | |
59 // Vin2+ -->|A1.0+ | -+- 100nF
60 // Vin2- -->|A1.0- | -+-
61 // Vin3+ -->|A2.0+ | |
62 // Vin3- -->|A2.0- AVss |---+
63 //
64 // T. Witt
65 // Yang Lu
66 // Texas Instruments, Inc
67 // June 2014
68 // Built with Code Composer Studio v5.5
69 //******************************************************************************
70 #include "driverlib.h"
71 
72 #define Num_of_Results 8
73 
74 /* Arrays to store SD24 conversion results */
78 uint16_t i = 0;
79 
80 void main(void) {
81  // Stop WDT
82  WDT_hold(WDT_BASE);
83 
84  // Internal ref
85  SD24_init(SD24_BASE, SD24_REF_INTERNAL);
86 
87  //Group with Channel 0
88  SD24_initConverterAdvancedParam param = {0};
89  param.converter = SD24_CONVERTER_0;
90  param.conversionMode = SD24_CONTINUOUS_MODE;
91  param.groupEnable = SD24_GROUPED;
92  param.inputChannel = SD24_INPUT_CH_ANALOG;
93  param.dataFormat = SD24_DATA_FORMAT_2COMPLEMENT;
94  param.interruptDelay = SD24_FOURTH_SAMPLE_INTERRUPT;
95  param.oversampleRatio = SD24_OVERSAMPLE_256;
96  param.gain = SD24_GAIN_1;
97  SD24_initConverterAdvanced(SD24_BASE, &param);
98 
99  //Group with Channel 1
100  param.converter = SD24_CONVERTER_1;
101  param.conversionMode = SD24_CONTINUOUS_MODE;
102  param.groupEnable = SD24_GROUPED;
103  param.inputChannel = SD24_INPUT_CH_ANALOG;
104  param.dataFormat = SD24_DATA_FORMAT_2COMPLEMENT;
105  param.interruptDelay = SD24_FOURTH_SAMPLE_INTERRUPT;
106  param.oversampleRatio = SD24_OVERSAMPLE_256;
107  param.gain = SD24_GAIN_1;
108  SD24_initConverterAdvanced(SD24_BASE, &param);
109 
110  // Enable interrupt
111  param.converter = SD24_CONVERTER_2;
112  param.conversionMode = SD24_CONTINUOUS_MODE;
113  param.groupEnable = SD24_NOT_GROUPED;
114  param.inputChannel = SD24_INPUT_CH_ANALOG;
115  param.dataFormat = SD24_DATA_FORMAT_2COMPLEMENT;
116  param.interruptDelay = SD24_FOURTH_SAMPLE_INTERRUPT;
117  param.oversampleRatio = SD24_OVERSAMPLE_256;
118  param.gain = SD24_GAIN_1;
119  SD24_initConverterAdvanced(SD24_BASE, &param);
120  SD24_enableInterrupt(SD24_BASE, SD24_CONVERTER_2, SD24_CONVERTER_INTERRUPT);
121 
122  // Delay ~200us for 1.2V ref to settle
123  __delay_cycles(3200);
124 
125  // Start conversion
126  SD24_startConverterConversion(SD24_BASE, SD24_CONVERTER_2);
127  // Enter LPM0 w/ interrupts
128  __bis_SR_register(LPM0_bits | GIE);
129 }
130 
131 #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
132 #pragma vector=SD24_VECTOR
133 __interrupt void SD24_ISR(void) {
134 #elif defined(__GNUC__)
135 void __attribute__ ((interrupt(SD24_VECTOR))) SD24_ISR (void) {
136 #else
137 #error Compiler not supported!
138 #endif
139  switch (__even_in_range(SD24IV,SD24IV_SD24MEM3)) {
140  case SD24IV_NONE: break;
141  case SD24IV_SD24OVIFG: break;
142  case SD24IV_SD24MEM0: break;
143  case SD24IV_SD24MEM1: break;
144  case SD24IV_SD24MEM2:
145  // Save CH0 results (clears IFG)
146  Ch0results[i] = SD24_getHighWordResults(SD24_BASE, SD24_CONVERTER_0);
147  // Save CH1 results (clears IFG)
148  Ch1results[i] = SD24_getHighWordResults(SD24_BASE, SD24_CONVERTER_1);
149  // Save CH2 results (clears IFG)
150  Ch2results[i] = SD24_getHighWordResults(SD24_BASE, SD24_CONVERTER_2);
151  i++;
152  if (i == Num_of_Results) {
153  i = 0;
154  __no_operation(); // SET BREAKPOINT HERE
155  }
156  break;
157  case SD24IV_SD24MEM3: break;
158  default: break;
159  }
160 }
MPU_initThreeSegmentsParam param
__no_operation()
__delay_cycles(500000)
uint16_t Ch0results[Num_of_Results]
uint16_t Ch2results[Num_of_Results]
uint16_t Ch1results[Num_of_Results]